package com.kfm.common.exception;

import com.kfm.common.domain.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import javax.naming.SizeLimitExceededException;

/**
 * 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class GlobalHandler {

    /**
     * 处理 ServerException 异常
     * @param e 异常
     */
    @ExceptionHandler(ServerException.class)
    public Result handlerServerException(ServerException e) {
        log.error(e.getMessage());
        return Result.failure(e.getMessage(), e.getCode());
    }

    /**
     * 处理 BadCredentialsException 异常 密码校验失败
     * @param e 异常
     */
    @ExceptionHandler(BadCredentialsException.class)
    public Result handlerBadCredentialsException(BadCredentialsException e) {
        log.error(e.getMessage());
        return Result.failure(e.getMessage());
    }
}
